************************************************************************
*** The Causal Effect of Education on Support for International Trade:  
*** Evidence from Compulsory Education Reforms
*** Omer Solodoch 
*** Replication code 1 
*** Note: replicators must install the following packages from the SSC Archive:
*** ssc install ivreg2
*** ssc install coefplot
*** ssc install esttab
*** ssc install rdrobust // or installing the rdrobust package from the github repository
*** net install rdrobust, from(https://raw.githubusercontent.com/rdpackages/rdrobust/master/stata) replace
*** net install rdlocrand, from(https://raw.githubusercontent.com/rdpackages/rdlocrand/master/stata) replace
*********************************************************************
clear all
* Set working directory
*global directory = "...\directory"
*******************************************
use IO7907data.dta
*******************************************


*******************************************
** Figure 1: first stage plot
*******************************************
set scheme rbn3mono

rdplot compulsory_educ RUNNING if WINDOW<=20, nbins(20 21) binselect(es) p(3) weights(WEIGHT) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) graph_options(graphregion(color(white)) scale(1.5) ytitle("Fraction completing compulsory education", size(small)) xtitle("Cohort relative to reform") legend(off) xlabel(-20(5)20, angle(horizontal))) 

*******************************************
** Table 3: main results, RDD
*******************************************
*** optimal window selection
rdbwselect pro_trade RUNNING, fuzzy(compulsory_educ) kernel(triangular) bwselect(mserd)  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  vce(cluster country_region) p(1)
**** Recommended window: BW est. mserd	12.209	12.209	19.955	19.955

*******************************************
* first stage F-statistic: 
*******************************************
ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) if WINDOW<=12, cl(country_region)
weakivtest
scalar Ffirst_comp=floor(r(F_eff))

ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) if WINDOW<=12, cl(country_region)
weakivtest
scalar Ffirst_schl=floor(r(F_eff))

estimate clear
{
eststo: rdrobust compulsory_educ RUNNING if pro_trade<.,  kernel(triangular) h(12.209) b(19.955) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)   vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Reform", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_comp, replace


eststo: rdrobust schooling13 RUNNING if pro_trade<., kernel(triangular) h(12.209) b(19.955) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)   vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Reform", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_schl, replace

eststo: rdrobust pro_trade RUNNING if compulsory_educ<., kernel(triangular) h(12.209) b(19.955) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)   vce(cluster country_region)
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Reform", replace
estadd local estimate="ITT", replace
estadd local clstr="Region", replace

eststo: rdrobust pro_trade RUNNING, fuzzy(compulsory_educ) kernel(triangular) h(12.209) b(19.955)  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)   vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Compulsory", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_comp, replace


eststo: rdrobust pro_trade RUNNING, fuzzy(schooling13) kernel(triangular) h(12.209) b(19.955) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)   vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Schooling", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_schl, replace

}

esttab  est1 est2 est3 est4 est5, ///
 se(3) b(3) replace star(* 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("First" "First" "ITT" "LATE" "LATE")    ///
 s(covs fixedef treat obs Ffirst, fmt(0 0 0 3)  label("Covariates" "Country-year FE" "Treatment" "Observations" "First-stage F-stat")) 


**********************************************************
** Figure 2: by survey year, RDD-local randomization
**********************************************************
*** optimal window
rdwinselect RUNNING sex1 citizen_parents1 ethnic_majority_group if compulsory_educ<.&protrade5<., nwindows(15) level(0.1)
** Recommended window is [-11.000; 11.000] with 19550 observations (8346 below, 11204 above).

** To produce the data table for figure 2 run:
estimate clear
eststo: rdrandinf pro_trade RUNNING if sex1<. & ethnic_majority_group<. & immigrant_parents<., wl(-11) wr(11) fuzzy(schooling13 tsls) ci(0.05)
	dis r(obs_stat)
	dis r(asy_pval)
	dis r(N)

eststo: rdrandinf pro_trade RUNNING if sex1<. & ethnic_majority_group<. & immigrant_parents<. & year==1995, wl(-11) wr(11) fuzzy(schooling13 tsls) ci(0.05)
	dis r(obs_stat)
	dis r(asy_pval)
	dis r(N)

eststo: rdrandinf pro_trade RUNNING if sex1<. & ethnic_majority_group<. & immigrant_parents<. & year==2003, wl(-11) wr(11) fuzzy(schooling13 tsls) ci(0.05)
	dis r(obs_stat)
	dis r(asy_pval)
	dis r(N)

eststo: rdrandinf pro_trade RUNNING if sex1<. & ethnic_majority_group<. & immigrant_parents<. & year==2013, wl(-11) wr(11) fuzzy(schooling13 tsls) ci(0.05)
	dis r(obs_stat)
	dis r(asy_pval)
	dis r(N)

esttab  est1 est2 est3 est4, ///
 drop(_cons) star(* 0.05 ** 0.01)   se(3) b(3) replace label  nonotes nogaps nodepvars   ///
 mtitles("Pooled" "1995" "2003" "2013")    
* To produce figure 2 using these data see "IO7907code2.do"



*******************************************************************************
** Table 4: Compulsory education, economic outcomes, and cultural protectionism
*******************************************************************************  
 
estimates clear
foreach var in pro_trade highsk manufacture offshorable_rti income_decileR TV_cultprot_d anti_foreign_culture_d {
	eststo: ivreg2 `var' sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if sample_skill==1,  cl(country_region)
estadd local modl "2SLS", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
*estadd local Ffirst=e(widstat), replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace
}

esttab  est1  est2  est3  est4  est5  est6 est7, ///
 keep(schooling13)  ///
 order(schooling13) ///
 se(3) b(3) replace star(* 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("Pro-trade" "Skilled" "manufacturing" "Offshorable" "Income" "Cultural1" "Cultural2")    ///
 s(covs fixedef N Ffirst, fmt(0 0 0 0)  label("Covariates" "Country-year FE" "Observations"  "First-stage F-statistic")) 


*******************************************************************************
** Figure 3: Effect of years of schooling by exposure to international trade
*******************************************************************************
estimates clear
foreach w of num 11 {
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & empstat1==0, cl(country_region)  
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & empstat1==1, cl(country_region)  

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & manufacture==0, cl(country_region)  
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & manufacture==1, cl(country_region)  

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & offshorable_bl==0, cl(country_region)  
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & offshorable_bl==1, cl(country_region)  
}

label var schooling13 `" "Schooling" "(2SLS)" "'


coefplot (est1, label(No) mcolor(gs8) ciopts(lcolor(gs8))) ///
(est2, label(Yes) mcolor(black) ciopts(lcolor(black))), bylabel("In paid work") ///
|| (est3, label(No)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est4, label(Yes) mcolor(black) ciopts(lcolor(black))), bylabel("Manufacturing") ///
|| (est5, label(No)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est6, label(Yes) mcolor(black) ciopts(lcolor(black))), bylabel("Offshorable occupation") ///
keep(schooling13) vert label yline(0, lc(maroon) lp(dash) lw(thin)) level(95) ///
  yti("Effect on support for trade") ///
  xscale(nofextend) yscale(range(-0.01 0.09)) ///
  ylabel(0(0.02)0.08, angle(horizontal)) ///
 scheme(s1mono) grid(none)   ///
subtitle(, size(medium) margin(medium) justification(center) ///
color(black) bcolor(white) box lcolor(black)) byopts(row(1)) legend(nobox region(lstyle(none)) cols(2) ring(0))
graph display, ysize(2.5) xsize(4)


*******************************************************************************
**Figure 4: Effect of years of schooling by the content of education 
*******************************************************************************
estimates clear
foreach w of num 11 {
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==2, robust
}

label var schooling13 `" "Schooling" "(2SLS)" "'

coefplot (est1, label(Below median) mcolor(gs8) ciopts(lcolor(gs8))) ///
(est2, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Pluralism in" "curriculum" "') ///
|| (est3, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est4, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Nationalism in" "curriculum" "') ///
|| (est5, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est6, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Patriotism in" "curriculum" "') ///
keep(schooling13) vert label yline(0, lc(maroon) lp(dash) lw(thin)) level(95) ///
 yti("Effect on support for trade") ///
  xscale(nofextend) yscale(range(-0.01 0.08)) ///
  ylabel(0(0.02)0.08, angle(horizontal)) ///
 scheme(s1mono) grid(none)   ///
subtitle(, size(medium) margin(medium) justification(center) ///
color(black) bcolor(white) box lcolor(black)) byopts(row(1)) legend(nobox region(lstyle(none)) cols(2) ring(0))
graph display, ysize(2.5) xsize(4)

******************************************************
***** statistical significance test 
******************************************************
qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edplural_med2==1, robust
local hzero=_b[schooling13]
qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edplural_med2==2, robust
test _b[schooling13]=`hzero'

qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edideolch_nat_med2==1, robust
local hzero=_b[schooling13]
qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edideolch_nat_med2==2, robust
test _b[schooling13]=`hzero'

qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edpatriot_med2==1, robust
local hzero=_b[schooling13]
qui ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11 & edpatriot_med2==2, robust
test _b[schooling13]=`hzero'
***************************


*******************************************************************************
** Appendix: 
*******************************************************************************

*******************************************************************************
**Table (A-2) Summary statistics for cohort-level V-Indoc measures
*******************************************************************************
tabstat pluralism patriotism nationalism mathscience if RUNNING<. & pro_trade <. &treat_first <. & IR==0, by(country_code) stat(mean sd min max)  long col(stat) format(%9.3f)

*******************************************************************************
** Figure A-1: First stage results by order of the global polynomial regression function
*******************************************************************************
rdplot compulsory_educ RUNNING if WINDOW<=20, nbins(20 21) binselect(es) p(1) weights(WEIGHT) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) graph_options(graphregion(color(white)) scale(1.5) ytitle("Fraction completing compulsory education", size(small)) xtitle("Cohort relative to reform") legend(off) xlabel(-20(5)20, angle(horizontal))) 

rdplot compulsory_educ RUNNING if WINDOW<=20, nbins(20 21) binselect(es) p(2) weights(WEIGHT) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) graph_options(graphregion(color(white)) scale(1.5) ytitle("Fraction completing compulsory education", size(small)) xtitle("Cohort relative to reform") legend(off) xlabel(-20(5)20, angle(horizontal))) 


*******************************************************************************
** Figure A-2: First-Stage by reform
*******************************************************************************
set scheme s1mono		
 foreach x in "AT (1962)" "DE (1949-69)" "DK (1958)" "ES (1970)" "FR (1967)" "GB (1947)" "GB (1972)" "IE (1972)" "NL (1975)" "SE (1962)" "HU (1961)" "PT (1964)" "CZ (1948-60)" "SK (1948)" "TW (1968)" "JP (1947)" "BG (1959)" "LV (1970)" "SI (1951)" {
	di "******************** Reform = `x' **********************"
	foreach y in compulsory_educ {
		rdplot `y' RUNNING if REFORM=="`x'" & WINDOW<=20, c(0) p(1) numbinl(20) numbinr(21) ///
graph_options(graphregion(color(white)) scale(1.5) ytitle("Fraction completing compulsory education", size(small)) xtitle("Cohort relative to reform") title("`x'") legend(off) xlabel(-20(5)20, angle(horizontal))) 	 
	}
}

*******************************************************************************
** Table A-3: The effect of compulsory education reforms on level of completed schooling
*******************************************************************************
estimate clear
foreach var in educyears_7 educyears_8 educyears_9 educyears_10 educyears_11 educyears_12 tertiary_educ   {
	*qui eststo: reg `var' treat_first RUNNING sex1 ethnic_majority_group citizen_parents1   i.year i.country  [aw=WEIGHT] if WINDOW<=11, cl(country_region)

*rdrandinf `var' RUNNING if sample_main==1, wl(-11) wr(11) 
 eststo: rdrobust `var' RUNNING if compulsory_educ<.,  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  vce(cluster country_region)
 estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace

}
esttab, ///
 se(3) b(3) replace star(+ 0.1 * 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("7 years" "8 years" "9 years" "10 years" "11 years" "12 years" "Tertiary") ///
 s(covs fixedef bw obs, fmt(0 0 0 0) label("Covariates" "Country-year FE" "Bandwidth" "Observations")) 

 
******************************************************************************* 
** Table A-4: The effect of compulsory education reforms on probability of completing compulsory schooling and years of schooling
*******************************************************************************
 estimate clear
foreach var in compulsory_educ schooling12 schooling13 educyears   {
eststo: rdrobust `var' RUNNING if compulsory_educ<.,  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  vce(cluster country_region)
 estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace

}
esttab, ///
 se(3) b(3) replace star(+ 0.1 * 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("Compulsory" "Schooling (12)" "Scooling (13)" "Schooling (22)") ///
 s(covs fixedef bw obs, fmt(0 0 0 0) label("Covariates" "Country-year FE" "Bandwidth" "Observations")) 

*******************************************************************************
** Figure A-4: Sorting test
*******************************************************************************
set scheme rbn3mono
hist RUNNING if WINDOW<=20, bin(41) fcolor(maroon) xlabel(-20(5)20, angle(horizontal)) xtitle("Cohort relative to reform") xline(-0.5, lp(dash) lc(black) lw(0.5)) scale(1.2)
rddensity RUNNING if WINDOW<=20, all hist_n(20 21) 

*******************************************************************************
** Figure A-5: Balance Test
*******************************************************************************
*** optimal window selection under local randomization, formal balance test for pretreatment covariates:
rdwinselect RUNNING sex1 citizen_parents1 ethnic_majority_group if compulsory_educ<.&protrade5<., nwindows(15) level(0.1)
** Recommended window is [-11.000; 11.000]: covariate balance up to [-11,11] birth cohorts around the cutoff 

*** visualization:
{
preserve
keep if RUNNING<.
keep if protrade5<.
foreach var in sex1 URBRURAL1 immigrant_parents ethnic_majority_group  {
  bysort REFORM RUNNING: gen `var'_N = _N
  egen `var'_m = mean(`var'), by(REFORM RUNNING)
  egen `var'_sd = sd(`var'), by(REFORM RUNNING)
  gen `var'_se = `var'_sd/sqrt(`var'_N)
  gen `var'_lower = `var'_m-(`var'_se*1.96)
  gen `var'_upper = `var'_m+(`var'_se*1.96)
    }
contract RUNNING treat_first sex1_m URBRURAL1_m immigrant_parents_m ethnic_majority_group_m WINDOW 
sort RUNNING
**panel (a) Male
scatter sex1_m RUNNING if WINDOW<=15, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform") ///
ytitle("Male") || lpolyci sex1_m RUNNING if WINDOW<=15 & treat_first==0, fcolor(gs12) || ///
lpolyci sex1_m RUNNING if WINDOW<=15 & treat_first==1, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal)) yscale(range(0 0.8)) ylabel(0(0.1)0.8)
**panel (b) Ethnic majority group
twoway (scatter ethnic_majority_group_m RUNNING if WINDOW<=15, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform")  yscale(range(0.4 1)) ylabel(0.4(0.1)1) ///
ytitle("Ethnic Majority Group")) || (lpolyci ethnic_majority_group_m RUNNING if WINDOW<=15 & treat_first==0, fcolor(gs12) yscale(range(0.4 1)) ylabel(0.4(0.1)1)) || ///
(lpolyci ethnic_majority_group_m RUNNING if WINDOW<=15 & treat_first==1, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal)) yscale(range(0.4 1)) ylabel(0.4(0.1)1))
**panel (c) Immigrant parents
scatter immigrant_parents_m RUNNING if WINDOW<=15, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform") ///
ytitle("Immigrant Parents") || lpolyci immigrant_parents_m RUNNING if WINDOW<=15 & treat_first==0, fcolor(gs12) || ///
lpolyci immigrant_parents_m RUNNING if WINDOW<=15 & treat_first==1, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal)) yscale(range(0 0.6)) ylabel(0(0.1)0.6)
**panel (d) Big city
scatter URBRURAL1_m RUNNING if WINDOW<=15, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform") ///
ytitle("Locality Type: Big City") || lpolyci URBRURAL1_m RUNNING if WINDOW<=15 & treat_first==0, fcolor(gs12) || ///
lpolyci URBRURAL1_m RUNNING if WINDOW<=15 & treat_first==1, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal))
restore
}

*******************************************************************************
** Figure (A-6) First Stage and Reduced Form
*******************************************************************************
{
preserve
keep if RUNNING<.
keep if protrade5<.
keep if RUNNING20<. & sex1<. & ethnic_majority_group<. & immigrant_parents<.
foreach var in compulsory_educ  pro_trade   {
  bysort REFORM RUNNING: gen `var'_N = _N
  egen `var'_m = mean(`var'), by(REFORM RUNNING)
  egen `var'_sd = sd(`var'), by(REFORM RUNNING)
  gen `var'_se = `var'_sd/sqrt(`var'_N)
  gen `var'_lower = `var'_m-(`var'_se*1.96)
  gen `var'_upper = `var'_m+(`var'_se*1.96)
    }
contract compulsory_educ_m pro_trade_m RUNNING treat_first WINDOW 
sort RUNNING
**panel (a) First-stage: compulsory education
scatter compulsory_educ_m RUNNING if WINDOW<=15 & compulsory_educ_m>=0.4, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform") ylabel(0.4(0.1)1) ///
ytitle("Fraction completing compulsory education") || lpolyci compulsory_educ_m RUNNING if WINDOW<=15 &treat_first==0, fcolor(gs12) || ///
lpolyci compulsory_educ_m RUNNING if WINDOW<=15 & treat_first==1, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal))
**panel (b) Reduced-form: pro-trade
scatter pro_trade_m RUNNING if WINDOW<=15, msize(tiny) mcolor(gs14) xline(-0.5, lp(dash)) xtitle("Cohort relative to reform") ylabel(0(0.1)0.6) ysc(range(0.1 0.4)) ///
ytitle("Fraction Supporting International Trade") || lpolyci pro_trade_m RUNNING if treat_first==0 & WINDOW<=15, fcolor(gs12) || ///
lpolyci pro_trade_m RUNNING if treat_first==1 & WINDOW<=15, fcolor(gs12) legend(off) xlabel(-15(5)15, angle(horizontal))
restore
}



******************************************************************************* 
** Table A-5: Placebo Cutoff Tests
*******************************************************************************
************************************************************************
** (a) ITT
************************************************************************
matrix ALL_RF_`j' = J(4,5,0)
	matrix rownames ALL_RF_`j' = "Reform" "p-value" "Bandwidth" "Observations" 
	matrix colnames ALL_RF_`j' = "(1) Reform-10" "(2) Reform-5" "(3) Reform" "(4) Reform+5" "(5) Reform+10"
	local i=0
	noisily di "********************  Reform = `x'  **********************"
	foreach cutoff of varlist RUNNING_minus10 RUNNING_minus5 RUNNING RUNNING_plus5 RUNNING_plus10 {
		local i=`i'+1
		rdrandinf pro_trade `cutoff' if sex1<. & ethnic_majority_group<. & immigrant_parents<., wl(-5) wr(5) fuzzy(compulsory_educ itt)
		matrix ALL_RF_`j'[1,`i'] = r(obs_stat)
		matrix ALL_RF_`j'[2,`i'] = r(randpval)
		matrix ALL_RF_`j'[3,`i'] = r(wr)
		matrix ALL_RF_`j'[4,`i'] = r(N)
	}
	noisily estout matrix(ALL_RF_`j', fmt("3 3 0 0"))
************************************************************************
** (b) LATE
************************************************************************
matrix ALL_RF_`j' = J(4,5,0)
	matrix rownames ALL_RF_`j' = "Reform" "p-value" "Bandwidth" "Observations" 
	matrix colnames ALL_RF_`j' = "(1) Reform-10" "(2) Reform-5" "(3) Reform" "(4) Reform+5" "(5) Reform+10"
	local i=0
	noisily di "********************  Reform = `x'  **********************"
	foreach cutoff of varlist RUNNING_minus10 RUNNING_minus5 RUNNING RUNNING_plus5 RUNNING_plus10 {
		local i=`i'+1
		rdrandinf pro_trade `cutoff' if sex1<. & ethnic_majority_group<. & immigrant_parents<., wl(-5) wr(5) fuzzy(compulsory_educ tsls)
		matrix ALL_RF_`j'[1,`i'] = r(obs_stat)
		matrix ALL_RF_`j'[2,`i'] = r(asy_pval)
		matrix ALL_RF_`j'[3,`i'] = r(wr)
		matrix ALL_RF_`j'[4,`i'] = r(N)
	}
		noisily estout matrix(ALL_RF_`j', fmt("3 3 0 0")) 

************************************************************************

estimate clear
**************************************************************************************************************************************
** Table A-6: Table (A-6) Effect of Secondary Education on Support for International Trade using Local Quadratic Polynomials
**************************************************************************************************************************************
*** DV: pro-trade 5-point scale
*** optimal window selection
rdbwselect protrade5 RUNNING, fuzzy(compulsory_educ) kernel(triangular) bwselect(mserd)  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  vce(cluster country_region) p(2)
*mserd |    17.901             17.901 |    24.882            24.882

ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) if WINDOW<=17, cl(country_region)
weakivtest
scalar Ffirst_comp=floor(r(F_eff))

ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) if WINDOW<=17, cl(country_region)
weakivtest
scalar Ffirst_schl=floor(r(F_eff))

 *estimate clear
{
eststo: rdrobust compulsory_educ RUNNING if pro_trade<.,  kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Compulsory", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_comp, replace


eststo: rdrobust schooling13 RUNNING if pro_trade<., kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Schooling", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_schl, replace

eststo: rdrobust protrade5 RUNNING if compulsory_educ<., kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Reform", replace
estadd local estimate="ITT", replace
estadd local clstr="Region", replace

eststo: rdrobust protrade5 RUNNING, fuzzy(compulsory_educ) kernel(triangular) h(17.901) b(24.882)  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Compulsory", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_comp, replace


eststo: rdrobust protrade5 RUNNING, fuzzy(schooling13) kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Schooling", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_schl, replace

eststo: rdrobust pro_trade RUNNING if compulsory_educ<., kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Reform", replace
estadd local estimate="ITT", replace
estadd local clstr="Region", replace

eststo: rdrobust pro_trade RUNNING, fuzzy(compulsory_educ) kernel(triangular) h(17.901) b(24.882)  covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Compulsory", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_comp, replace


eststo: rdrobust pro_trade RUNNING, fuzzy(schooling13) kernel(triangular) h(17.901) b(24.882) covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off) p(2) vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local main_ef=e(tau_cl), replace
estadd local main_se=e(se_tau_cl), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="Schooling", replace
estadd local estimate="LATE", replace
estadd local clstr="Region", replace
estadd local Ffirst=Ffirst_schl, replace


}


 esttab  est1 est2 est3 est4 est5 est6 est7 est8, ///
 se(3) b(3) replace star(+ 0.1 * 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("First" "First" "ITT" "LATE" "LATE" "ITT" "LATE" "LATE")    ///
 s(DV treat covs fixedef obs Ffirst, fmt(0 0 0 0 0 0 3)  label("DV:" "Treatment:" "Covariates" "Country-year FE" "Observations" "First-stage F-stat")) 

***************************************************************************************************************
** Figure A-7: Compulsory Schooling Effect by Bandwidth
***************************************************************************************************************
** To produce the data table for figure A-7 run:
**panel (a): without covariates
forval w=1/20 {
	qui ivreg2 pro_trade i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w', first robust
	display _b[compulsory_educ]
	display _se[compulsory_educ]
}

**panel (b): with covariates
forval w=1/20 {
	qui ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w', first robust
	display _b[compulsory_educ]
	display _se[compulsory_educ]
}
** To produce figure A-7 using these data see "IO7907code2.do"

***************************************************************************************************************
** Table A-7: Effect of compulsory schooling on support for trade, alternative measures of schooling, continuity-based RD framework
***************************************************************************************************************
  estimate clear
foreach var in compulsory_educ schooling12 schooling13 educyears   {
eststo: rdrobust pro_trade RUNNING if compulsory_educ<., fuzzy(`var') covs(sex1 ethnic_majority_group immigrant_parents year2 year3 AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE) bwrestrict(off)  vce(cluster country_region)
estadd local fst_ef=round(e(tau_T_cl), 0.001), replace
estadd local fst_se=round(e(se_tau_T_cl), 0.001), replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local obs=e(N_h_l)+e(N_h_r), replace
estadd local bw=floor(e(h_r)), replace
estadd local DV=e(outcomevar) , replace
estadd local treat="`var'", replace
estadd local estimate="LATE", replace
}

esttab, ///
 se(3) b(3) replace star(+ 0.1 * 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("Compulsory" "Schooling (12)" "Scooling (13)" "Schooling (22)") ///
 s(covs fixedef bw obs, fmt(0 0 0 0) label("Covariates" "Country-year FE" "Bandwidth" "Observations")) 


***************************************************************************************************************
** Table A-8: Effect of compulsory schooling on support for trade, alternative measures of schooling, local randomization RD framework
***************************************************************************************************************
gen schooling_var=.
label var schooling_var "Schooling"
estimate clear
foreach var in compulsory_educ schooling12 schooling13 educyears   {
replace schooling_var=`var'
eststo: ivreg2 pro_trade   sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling_var = treat_first) [aw=WEIGHT] if WINDOW<=11, cl(country_region)
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local treat="`var'", replace
estadd local bw=11, replace
weakivtest
quietly estadd scalar Ffirst=floor(r(F_eff)), replace
}
esttab, ///
 keep(schooling_var) ///
 se(3) b(3) replace star(+ 0.1 * 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("Compulsory" "Schooling (12)" "Scooling (13)" "Schooling (22)") ///
 s(covs fixedef treat bw N Ffirst, fmt(0 0 0 0 0) label("Covariates" "Country-year FE" "Treatment" "Bandwidth" "Observations" "First stage F-stat")) 


***************************************************************************************************************
** Figure A-8: Country-by-country exclusion
***************************************************************************************************************
** To produce the data table for figure A-8 run:

foreach country in AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE UK {
qui ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=11 & `country'==0, robust
	display _b[compulsory_educ]
}
foreach country in AT BG TW CZ DK FR DE HU IR JP LV NL PT SK SI ES SE UK {
qui ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=11 & `country'==0, robust
	display _se[compulsory_educ]
}

** None excluded:
qui ivreg2 pro_trade sex1 ethnic_majority_group citizen_parents1 i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=13, robust 
display _b[compulsory_educ]
display _se[compulsory_educ]
** To produce figure A-8 using these data see "IO7907code2"


***************************************************************************************************************
** Figure A-9: Effect of years of schooling by the content of education, including focus on math and science 
***************************************************************************************************************
estimates clear
foreach w of num 11 {
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_med2==2, robust
}

label var schooling13 `" "Schooling" "(2SLS)" "'


coefplot (est1, label(Below median) mcolor(gs8) ciopts(lcolor(gs8))) ///
(est2, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Pluralism in" "curriculum" "') ///
|| (est3, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est4, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Nationalism in" "curriculum" "') ///
|| (est5, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est6, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Patriotism in" "curriculum" "') ///
|| (est7, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est8, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Focus on math" "and science" "') ///
keep(schooling13) vert label yline(0, lc(maroon) lp(dash) lw(thin)) level(95) ///
 yti("Effect on support for trade") ///
  xscale(nofextend) yscale(range(-0.01 0.08)) ///
  ylabel(0(0.02)0.08, angle(horizontal)) ///
 scheme(s1mono) grid(none)   ///
subtitle(, size(medium) margin(medium) justification(center) ///
color(black) bcolor(white) box lcolor(black)) byopts(row(1)) legend(nobox region(lstyle(none)) cols(2) ring(0))
graph display, ysize(2.5) xsize(4)

*****************************************************************************************************
** Figure A-10: Effect of schooling years by the content of education, lower vs. upper tercile
*****************************************************************************************************

estimates clear
foreach w of num 11 {
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_trc2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_trc2==3, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_trc2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_trc2==3, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_trc2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_trc2==3, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_trc2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_trc2==3, robust
}

label var schooling13 `" "Schooling" "(2SLS)" "'


coefplot (est1, label(Lower tercile) mcolor(gs8) ciopts(lcolor(gs8))) ///
(est2, label(Upper tercile) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Pluralism in" "curriculum" "') ///
|| (est3, label(Lower tercile)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est4, label(Upper tercile) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Nationalism in" "curriculum" "') ///
|| (est5, label(Lower tercile)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est6, label(Upper tercile) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Patriotism in" "curriculum" "') ///
|| (est7, label(Lower tercile)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est8, label(Upper tercile) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Focus on math" "and science" "') ///
keep(schooling13) vert label yline(0, lc(maroon) lp(dash) lw(thin)) level(95) ///
 yti("Effect on support for trade") ///
  xscale(nofextend) yscale(range(-0.02 0.11)) ///
  ylabel(-0.02(0.02)0.1, angle(horizontal)) ///
 scheme(s1mono) grid(none)   ///
subtitle(, size(medium) margin(medium) justification(center) ///
color(black) bcolor(white) box lcolor(black)) byopts(row(1)) legend(nobox region(lstyle(none)) cols(2) ring(0))
graph display, ysize(2.5) xsize(4) 

*****************************************************************************************************
** Figure A-11: Effect of compulsory schooling by the content of education
*****************************************************************************************************
estimates clear
foreach w of num 11 {
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edplural_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edideolch_nat_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edpatriot_med2==2, robust

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_med2==1, robust
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1   i.year i.country (compulsory_educ = treat_first) [aw=WEIGHT] if WINDOW<=`w' & edmath_med2==2, robust
}

label var compulsory_educ `" "Compulsory education" "(2SLS)" "'


coefplot (est1, label(Below median) mcolor(gs8) ciopts(lcolor(gs8))) ///
(est2, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Pluralism in" "curriculum" "') ///
|| (est3, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est4, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Nationalism in" "curriculum" "') ///
|| (est5, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est6, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Patriotism in" "curriculum" "') ///
|| (est7, label(Below median)  mcolor(gs8) ciopts(lcolor(gs8))) ///
(est8, label(Above median) mcolor(black) ciopts(lcolor(black))), bylabel(`" "Focus on math" "and science" "') ///
keep(compulsory_educ) vert label yline(0, lc(maroon) lp(dash) lw(thin)) level(95) ///
 yti("Effect on support for trade") ///
  xscale(nofextend) yscale(range(-0.1 0.4)) ///
  ylabel(-0.1(0.1)0.4, angle(horizontal)) ///
 scheme(s1mono) grid(none)   ///
subtitle(, size(medium) margin(medium) justification(center) ///
color(black) bcolor(white) box lcolor(black)) byopts(row(1)) legend(nobox region(lstyle(none)) cols(2) ring(0))
graph display, ysize(2.5) xsize(4)


*****************************************************************************************************
** Table A-9: Effect of schooling years and cohort-specific content of education on support for trade
** LPM and 2SLS
*******************************************************************************
estimates clear
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath sex1 ethnic_majority_group citizen_parents1   i.year i.country  [aw=WEIGHT] if WINDOW<=11 & treat_first<., robust
estadd local modl "OLS", replace
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath Zschool_plural2  i.agecat sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local modl "OLS", replace
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath Zschool_patriot2  i.agecat sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local modl "OLS", replace
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath Zschool_math2  i.agecat  sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local modl "OLS", replace
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace


eststo: ivreg2 pro_trade ZCCv2edplural ZCCv2edpatriot ZCCv2edmath sex1 ethnic_majority_group citizen_parents1   i.year i.country (Zschooling13 = treat_first) [aw=WEIGHT] if WINDOW<=11, robust
estadd local modl "2SLS", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local Ffirst=e(widstat), replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace

eststo: ivreg2 pro_trade ZCCv2edplural ZCCv2edpatriot ZCCv2edmath sex1 ethnic_majority_group citizen_parents1   i.year i.country (Zschooling13 Zschool_plural2 = treat_first IV_educ_plural2) [aw=WEIGHT] if WINDOW<=11, robust
estadd local modl "2SLS", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local Ffirst=floor(e(widstat)), replace

eststo: ivreg2 pro_trade ZCCv2edplural ZCCv2edpatriot ZCCv2edmath  sex1 ethnic_majority_group citizen_parents1   i.year i.country (Zschooling13 Zschool_patriot2  = treat_first IV_educ_patriot2) [aw=WEIGHT] if WINDOW<=11, robust
estadd local modl "2SLS", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local Ffirst=floor(e(widstat)), replace

eststo: ivreg2 pro_trade ZCCv2edplural ZCCv2edpatriot ZCCv2edmath  sex1 ethnic_majority_group citizen_parents1   i.year i.country (Zschooling13 Zschool_math2 = treat_first IV_educ_math2) [aw=WEIGHT] if WINDOW<=11, robust
estadd local modl "2SLS", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
estadd local Ffirst=floor(e(widstat)), replace

esttab  est1 est2 est3 est4 est5 est6 est7 est8 ///
 ,keep(Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath Zschool_plural2 Zschool_patriot2 Zschool_math2)  ///
 order(Zschooling13 ZCCv2edplural ZCCv2edpatriot ZCCv2edmath Zschool_plural2 Zschool_patriot2 Zschool_math2) ///
 se(3) b(3) replace star(* 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("LPM" "LPM" "LPM" "LPM" "IV" "IV" "IV" "IV")    ///
 s(covs fixedef N r2 Ffirst, fmt(0 0 0 3 0) label("Covariates" "Country-year FE" "Observations" "R-squared"  "First-stage F-statistic")) 

 
********************************************************************************************
** Table A-10: learning outcomes:
********************************************************************************************
estimates clear
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean sex1 ethnic_majority_group citizen_parents1   i.year i.country  [aw=WEIGHT] if WINDOW<=11 & treat_first<., robust
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean Zschool_plural2  i.agecat sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean Zschool_patriot2  i.agecat sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace
eststo: reg pro_trade Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean Zschool_lo_score  i.agecat  sex1 ethnic_majority_group citizen_parents1  i.year i.country if WINDOW<=11 & treat_first<., robust
estadd local covs "\checkmark", replace
estadd local fixedef "\checkmark", replace

esttab  est1 est2 est3 est4,  ///
 keep(Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean Zschool_plural2 Zschool_patriot2 Zschool_lo_score)  ///
 order(Zschooling13 ZCCv2edplural ZCCv2edpatriot Zana_lo_score_mean Zschool_plural2 Zschool_patriot2 Zschool_lo_score) ///
 se(3) b(3) replace star(* 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("" "" "" "")    ///  
 s(covs fixedef N r2, fmt(0 0 0 3) label("Covariates" "Country-year FE" "Observations" "R-squared")) 
 
********************************************************************************************
** Table E-5: excluding respondents with potential exposure to economics education:
********************************************************************************************

estimates clear
eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if sample_skill==1,  cl(country_region)
estadd local gensch "included", replace
estadd local vocsch "included", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if sample_skill==1 & noecon_educ==1,  cl(country_region)
estadd local gensch "excluded", replace
estadd local vocsch "included", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if sample_skill==1 & econ_vocational==0,  cl(country_region)
estadd local gensch "included", replace
estadd local vocsch "excluded", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace

eststo: ivreg2 pro_trade  sex1 ethnic_majority_group citizen_parents1 i.year i.country (schooling13 = treat_first) [aw=WEIGHT] if sample_skill==1 & noecon_educ==1 & econ_vocational==0,  cl(country_region)
estadd local gensch "excluded", replace
estadd local vocsch "excluded", replace
estadd local fixedef "\checkmark", replace
estadd local covs "\checkmark", replace
weakivtest
quietly estadd scalar Ffirst=r(F_eff), replace

esttab  est1  est2 est3 est4, ///
 keep(schooling13)  ///
 order(schooling13) ///
 se(3) b(3) replace star(* 0.05 ** 0.01)  label  nonotes nogaps nodepvars   ///
 mtitles("Pro-trade" "Pro-trade" "Pro-trade" "Pro-trade")    ///
 s(covs fixedef gensch vocsch N Ffirst, fmt(0 0 0 3 0)  label("Covariates" "Country-year FE" "Countries with economics in general schools" "Respondents with potential exposure to economics in specialized education" "Observations" "First-stage F-statistic")) 
